<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>收银员管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
	<link rel="shortcut icon" href="favicon.ico"> 
	<link href="${ctxStatic}/plugins/h+/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
	
    <!-- Data Tables -->
    <link href="${ctxStatic}/plugins/h+/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
	<!--新增css-->
    <link href="${ctxStatic}/xmarket/css/newplus.css" rel="stylesheet">
	
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>

    </script>
	<style>
	
	</style>
</head>

<body class="gray-bg">
	<%--<div class="row border-bottom">--%>
		<%--<nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">--%>
			<%--<div class="navbar-header">--%>
				<%--<a class="navbar-minimalize minimalize-styl-2a " href="javascript:;">--%>
					<%--<img src="${ctxStatic}/xmarket/img/jl_logo.png" />--%>
				<%--</a>--%>
				<%--<div class="navbar-form-custom nav-name-longwidth">--%>
					<%--<div class="jl-logoright-name">--%>
						<%--<div class="logoright-name-big">辽宁线下体验店</div>--%>
						<%--<div class="logoright-name-small">辽宁线下体验店</div>--%>
					<%--</div>--%>
				<%--</div>--%>
			<%--</div>--%>
			<%--<ul class="nav navbar-top-links navbar-right">--%>
				<%--<li class="hidden-xs">--%>
					<%--<a href="javascript:;" class="J_menuItem" data-index="0"><i class="fa fa-sign-out"></i> 注销</a>--%>
				<%--</li>--%>
			<%--</ul>--%>
		<%--</nav>--%>
	<%--</div>--%>
	
	<div class="ibox float-e-margins">
		<div class="ibox-title newtitle_height">
			<h5 style="margin-top:8px;">收银员管理</h5> 
			<div class="ibox-tools">
				<div class="text-center">
					<a class="btn btn-jlorange addnewtr" href="javascript:;" style="color:#fff;">新增收银员</a>
				</div>
			</div>
		</div>
	</div>
	
	<div class="row">
		<div class="col-sm-12 ibox-content">
			<table class="table table-striped table-bordered table-hover" id="cashierstable">
				<thead>
					<tr>
						<th>收银员</th>
						<th>手机号</th>
						<th>是否启用</th>
						<th>操作</th>
						<th>删除</th>
					</tr>
				</thead>
				<tbody id="clerkList">
				</tbody>
			</table>
		</div>
	</div>
	
	<div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h5 class="modal-title">新增收银员</h5>
				</div>
				<form class="" id="form">
					<div class="modal-body">
						<div class="infolist">
							<label>姓名：</label><input type="text" placeholder="姓名" class="form-control" id="person_name" name="user.person_name">
						</div>
						<div class="infolist">
							<label>用户名：</label><input type="text" placeholder="用户名" class="form-control" id="login_name" name="user.login_name">
						</div>
						<div class="infolist">
							<label>密码：</label><input type="password" placeholder="密码" class="form-control" id="pwd" name="user.pwd">
						</div>
						<div class="infolist">
							<label>手机号：</label><input type="text" placeholder="手机号" class="form-control" id="phone" name="user.phone">
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-white" data-dismiss="modal" >取消</button>
						<button type="button" class="btn btn-primary" onclick="phone_AddClerk()">添加</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	
	<div class="modal inmodal fade" id="setpswpop" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h5 class="modal-title">重置密码</h5>
				</div>
				<form class="" id="pwdForm">
					<div class="modal-body">
						<div class="infolist">
							<input type="hidden" id="userId" name="user.id">
							<label>新密码：</label><input id="newPwd" name="user.newPwd" type="password" placeholder="新密码" class="form-control">
							<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 密码长度至少4个字符，最多16个字符</span>
						</div>
						<div class="infolist">
							<label>确认密码：</label><input id="rePwd" name="user.rePwd" type="password" placeholder="确认密码" class="form-control">
							<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
						</div>
						<div class="infolist">
							<label>管理员密码：</label><input id="adminPwd" name="user.adminPwd" type="password" placeholder="管理员密码："  class="form-control">
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" onclick="updatePwd();">确定</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	
	<div class="modal inmodal fade" id="changetel" tabindex="-1" role="dialog"  aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
					<h5 class="modal-title">修改手机号</h5>
				</div>
				<form class="" id="">
					<div class="modal-body">
						<div class="infolist">
							<label>输入新手机号：</label><input id="newPhone" name="" type="text" placeholder="" class="form-control">
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" onclick="updatePhone();">确定</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	
    <script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/jeditable/jquery.jeditable.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script>
        $(function(){
            //加载收银员
            loadClerk();

        })
	</script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
	
	<script>

		$(".delcur").click(function(){
			if(confirm("确定要删除吗?")){  
				$(this).parents("tr").remove(); 
			}			
		})
		
		$(".addnewtr").click(function() {
			$("#myModal6").modal(open);
		});
		function opensetpsw(id){
		    $("#userId").val(id);
			$("#setpswpop").modal('show');
		}
		function closesetpsw(){
			$("#setpswpop").modal('hide');
		}
		
		function openchangetel(id){
            $("#userId").val(id);
			$("#changetel").modal('show');
		}
		function closechangetel(){
			$("#changetel").modal('hide');
		}
		
		function closemodal(){
			$("#myModal6").modal('hide');
			$("#cashierstable tbody").append('<tr class="gradeX"><td>曲奇</td><td><div class="switch"><div class="onoffswitch"><input type="checkbox" checked="" class="onoffswitch-checkbox" id="example2"><label class="onoffswitch-label" for="example2"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></div></td><td><a class="btn btn-jlorange btntwomoregroups" href="javascript:;" style="color:#fff;">重置密码</a><a class="btn btn-jlorange btntwomoregroups" href="javascript:;" style="color:#fff;">修改手机号</a></td><td><a class="btn btn-jlorange btntwomoregroups delcur" href="javascript:;" style="color:#fff;">删除店员</a></td></tr>');
		}
		
		function checkPhone(){ 
			var phone = document.getElementById('newtelnum').value;
			if(!(/^1[34578]\d{9}$/.test(phone))){ 
				alert("手机号码有误，请重填");  
				return false; 
			} else{
				$("#changetel").modal('hide');
			}
		}

		//新增店员
		function phone_AddClerk(){
		    var person_name=$("#person_name").val();
		    var login_name=$("#login_name").val();
		    var pwd=$("#pwd").val();
		    var phone=$("#phone").val();
		    var msg="";
		    var flag=true;
		    if(person_name==null||person_name==""){
				flag=false;
				msg="姓名不能为空！";
			}else if(login_name==null||login_name==""){
		        flag=false;
		        msg="用户名不能为空！";
			}else if(pwd==null||pwd==""){
				flag=false;
				msg="密码不能为空！";
			}else if(phone==null||phone==""){
			    flag=false;
			    msg="手机号不能为空！";
			}else if(!(/^1[34578]\d{9}$/.test(phone))){
			    flag=false;
                msg="手机号码有误，请重填";
			}
			if(flag){
                $.ajax( {
                    url:'${pageContext.request.contextPath}/api/QTClerk/QTinsertClerk.ac',// 跳转到 action
                    data:$("#form").serialize(),
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.return_code==0){
                            alert(data.return_info);
                        }else{
                            loadClerk();
                            alert(data.return_info);
                            $("#myModal6").modal('hide');

                        }
                    },
                    error : function() {

                    }
                });
			}else{
			    alert(msg);
            }


		}

		//加载收银员
		function loadClerk(){
            $.ajax( {
                url:'${pageContext.request.contextPath}/api/QTClerk/QTqueryClerk.ac',// 跳转到 action
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    var list=data.return_data;
                    var html='';
                    for(var i=0;i<list.length;i++){
						html+='<tr class="gradeX"><td>'+list[i].personName+'</td>'+
								'<td>'+list[i].phone+'</td>'+
                            '						<td>'+
                            '							<div class="switch">'+
                            '								<div class="onoffswitch">';
								if(list[i].islock=='0'){
						html+='<input type="checkbox" checked class="onoffswitch-checkbox"  id="'+list[i].user_code+'" onclick="changeState(\''+list[i].user_code+'\')">';
                                }else{
						html+='<input type="checkbox"  class="onoffswitch-checkbox" id="'+list[i].user_code+'" onclick="changeState(\''+list[i].user_code+'\')">';
                                }
                        html+='									<label class="onoffswitch-label" for="'+list[i].user_code+'">'+
                            '										<span class="onoffswitch-inner"></span>'+
                            '										<span class="onoffswitch-switch"></span>'+
                            '									</label>'+
                            '								</div>'+
                            '							</div>'+
                            '						</td>'+
                            '						<td>'+
                            '							<a class="btn btn-jlorange btntwomoregroups" href="javascript:;" style="color:#fff;" onclick="opensetpsw(\''+list[i].user_code+'\');">重置密码</a>'+
                            '							<a class="btn btn-jlorange btntwomoregroups" href="javascript:;" style="color:#fff;" onclick="openchangetel(\''+list[i].user_code+'\');">修改手机号</a>'+
                            '						</td>'+
                            '						<td>'+
                            '							<a class="btn btn-jlorange btntwomoregroups delcur" href="javascript:;" style="color:#fff;" onclick="delClerk(\''+list[i].user_code+'\')">删除店员</a>'+
                            '						</td></tr>';
                    }
                    $("#clerkList").html(html);
                }
            });

		}
		//删除店员
		function delClerk(user_code){
            if(confirm("确定要删除吗?")){
                $.ajax( {
                    url:'${pageContext.request.contextPath}/api/QTClerk/delClerk.ac?user_code='+user_code,// 跳转到 action
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.return_code==0){
                            alert(data.return_info);
                        }else{
                            loadClerk();
                            alert(data.return_info);
                            $("#myModal6").modal('hide');

                        }
                    }
                });
            }
		}
//修改密码
		function updatePwd(){
			var newPwd=$("#newPwd").val();
			var rePwd=$("#rePwd").val();
			var adminPwd=$("#adminPwd").val();
			var flag=true;
			if(newPwd==null||newPwd==""){
				flag=false;
				msg="新密码不能为空！";
			}else if(rePwd==null||rePwd==""){
			    flag=false;
			    msg="确认密码不能为空！";
			}else if(adminPwd==null||adminPwd==""){
			    flag=false;
			    msg="管理员密码不能为空！";
			}else if(newPwd!=rePwd){
			    flag=false;
			    msg="新密码和确认密码不一致！";
			}
			if(flag){
                $.ajax( {
                    url:'${pageContext.request.contextPath}/api/QTClerk/updatePwd.ac',// 跳转到 action
                    type:'post',
                    data:$("#pwdForm").serialize(),
					cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.return_code==0){
                            alert(data.return_info);
                        }else{
                            loadClerk();
                            alert(data.return_info);
                            closesetpsw();

                        }
                    }
                });
			}else{
			    alert(msg);
			}

		}
//修改手机号
		function updatePhone(){
		    var newPhone=$("#newPhone").val();
		    var userId=$("#userId").val();
		    if(newPhone==null||newPhone==""){
		        alert("手机号不能为空");
			}else if(!(/^1[34578]\d{9}$/.test(newPhone))){
		        alert("手机号格式不正确");
			}else{
                $.ajax( {
                    url:'${pageContext.request.contextPath}/api/QTClerk/phone_updatePhone.ac?id='+userId+'&phone='+newPhone,// 跳转到 action
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        if(data.return_code==0){
                            alert(data.return_info);
                        }else{
                            loadClerk();
                            alert(data.return_info);
                            closechangetel();

                        }
                    }
                });
			}
		}
//修改状态
		function changeState(id){
		    var flag=$("#"+id).prop("checked");
            $.ajax( {
                url:'${pageContext.request.contextPath}/api/QTClerk/phone_LockClerk.ac?id='+id+'&flag='+flag,// 跳转到 action
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data.return_code==0){
                        alert(data.return_info);
                    }else{
//                        loadClerk();
                        alert(data.return_info);

                    }
                }
            });


		}
	</script>
    
</body>

</html>